﻿using SdtpsLibrary;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace sdtps
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 开启服务
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            try
            {
                GRPCServer.GRPCServer.viewctrl = richTextBox1;
                TaskHanle.viewctrl = richTextBox1;

                string msg= GRPCServer.GRPCServer.StartServer();
         
                richTextBox1.Text +=string.Format("{0}\t{1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), msg);// StartServer();
                richTextBox1.Text += "开启成功\r\n";
              
            }
            catch (Exception cw)
            {
                richTextBox1.Text = cw.Message + "\r\n" + cw.StackTrace;
            }
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
          //  richTextBox1.Text = DateTime.Now.ToString("y");
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            
        }

        private void tsButton3_Click(object sender, EventArgs e)
        {
            DataTable mydt1 = new DataTable("tasktypeconfig");
            mydt1.Columns.Add("name");
            mydt1.Columns.Add("objjc");
            mydt1.Columns.Add("tasktype");
            mydt1.Columns.Add("dllname");
            mydt1.Columns.Add("classname");
            mydt1.Columns.Add("enable",typeof(Boolean));
            mydt1.Columns.Add("objorder", typeof(int));
            mydt1.Columns.Add("singleton", typeof(Boolean));

            DataSet myds1 = new DataSet("taskconfig"); 
            myds1.Tables.Add(mydt1);

            mydt1.Rows.Add(new object[] { "test", "测试用", "test", "sdtpstest.dll", "sdtpstest.test", true, 1 ,true});
            mydt1.AcceptChanges();

            string filename = System.IO.Path.Combine(Application.StartupPath, "sdtpstask.config");
            myds1.WriteXml(filename, XmlWriteMode.WriteSchema);

        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            GRPCServer.GRPCServer.StopServer();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            toolStripButton1_Click(sender, e);
        }
    }
}
